package interfaces.clients.authorization;

import java.io.File;

/**
 * Authorization test 2.
 *
 * This method must be executed twice. Before the first running
 * the database file must be deleted.
 *
 * @author Manujlov Maxim
 */
public class AuthorizationTest2 {
  public static void main(String[] args) {
    try {
      File f = new File(interfaces.common.ServerSettings.getWorkingDir(),
                              interfaces.common.ServerSettings.getUsersDatabaseFileName());
      if (!(f.exists())) { // the first running
        Authorizer a = AuthorizationSystem.getInstance();
        a.addUser(new AuthorizationData("Tom", "qwerty"));
        a.addUser(new AuthorizationData("Jack", "123456"));
        System.out.println("OK. Run program again.");
      }
      else if (f.exists()) { // the second running
        Authorizer a = AuthorizationSystem.getInstance();
        a.authorize(new AuthorizationData("Tom", "qwerty"));
        a.authorize(new AuthorizationData("Jack", "123456"));
        System.out.println("Test passed.");
      }
    }
    catch (Throwable e) {
      System.out.println("Test failed.");
      e.printStackTrace();
    }
  }
}
